//
//  NewTaskHeaderView.m
//  BaishidaiKnight
//
//  Created by mac book on 2019/1/28.
//  Copyright © 2019年 sy. All rights reserved.
//

#import "NewTaskHeaderView.h"


@interface NewTaskHeaderView ()

@property(nonatomic,strong) UILabel * shipFeeLabel;
@property(nonatomic,strong) UILabel * createTimeLabel;
@property(nonatomic,strong) UIView * lineView;
@end


@implementation NewTaskHeaderView


-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        
        [self createSubviews];
    }
    return self;
}


#pragma mark - createSubviews
-(void)createSubviews{


    [self addSubview:self.shipFeeLabel];
    [self addSubview:self.createTimeLabel];
    [self addSubview:self.lineView];
    
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self);
        make.left.right.equalTo(self);
        make.height.mas_equalTo(1);
        
    }];
    
    [self.shipFeeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self);
        make.left.equalTo(self);
        make.width.equalTo(self).multipliedBy(0.5);
        make.bottom.equalTo(self.lineView.mas_top);

    }];
    
    [self.createTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.bottom.equalTo(self.shipFeeLabel);
        make.left.equalTo(self.shipFeeLabel.mas_right);
        make.right.equalTo(self);

    }];
    
    
    
    
}


-(void)setTaskModel:(TaskModel *)taskModel{
    
    
    _taskModel = taskModel;
    NSString* time =  @"";
    NSString* mark =  @"";
    time = [CommonUntils timeStampConvertToDateString:taskModel.add_time formate:@"HH:mm"];
    mark =  @"接单时间";
    
    NSString* money = [NSString stringWithFormat:@"￥%@",taskModel.returnpay];
    NSString* shouyi = [NSString stringWithFormat:@"+%@(奖励)",taskModel.extra_reward];
    NSString*strMoney = [NSString stringWithFormat:@"%@ %@ \n 本单预计收入",money,shouyi];
    NSMutableAttributedString* attributeStr  = [[NSMutableAttributedString alloc]initWithString:strMoney];
    [attributeStr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:24.f],NSForegroundColorAttributeName:[UIColor colorWithRed:248/255.f green:159/255.f blue:39/255.f alpha:1.0]} range:[strMoney rangeOfString:money]];
    
    [attributeStr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10.f],NSForegroundColorAttributeName:[UIColor redColor]} range:[strMoney rangeOfString:shouyi]];
    
    [attributeStr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10.f],NSForegroundColorAttributeName:[UIColor lightGrayColor]} range:[strMoney rangeOfString:@"(奖励)"]];
    [attributeStr addAttribute:NSBaselineOffsetAttributeName value:@(0.35 * (24 - 10)) range:[strMoney rangeOfString:shouyi]];
    
    
    self.shipFeeLabel.attributedText = attributeStr;
    self.shipFeeLabel.textAlignment = NSTextAlignmentCenter;
    
    
    NSString* strTime = [NSString stringWithFormat:@"%@ \n %@",time, mark];
    attributeStr  = [[NSMutableAttributedString alloc]initWithString:strTime];
    [attributeStr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:24.f],NSForegroundColorAttributeName:[UIColor colorWithRed:248/255.f green:159/255.f blue:39/255.f alpha:1.0]} range:[strTime rangeOfString:time]];
    self.createTimeLabel.attributedText = attributeStr;
    self.createTimeLabel.textAlignment = NSTextAlignmentCenter;
    
    
}


#pragma mark - 懒加载

-(UILabel *)shipFeeLabel{
    if(!_shipFeeLabel){
        _shipFeeLabel = [[UILabel alloc]init];
        _shipFeeLabel.numberOfLines = 0;
        _shipFeeLabel.lineBreakMode = NSLineBreakByCharWrapping;
        _shipFeeLabel.font = [UIFont systemFontOfSize:14.f];
        _shipFeeLabel.textColor =kMyColor(113, 113, 113);
    }
    return _shipFeeLabel;
}

-(UILabel *)createTimeLabel{
    if(!_createTimeLabel){
        _createTimeLabel = [[UILabel alloc]init];
        _createTimeLabel.numberOfLines = 0;
        _createTimeLabel.lineBreakMode = NSLineBreakByCharWrapping;
        _createTimeLabel.font = [UIFont systemFontOfSize:14.f];
        _createTimeLabel.textColor = kMyColor(113, 113, 113);
    }
    return _createTimeLabel;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = kMyColor(231, 231, 231);
    }
    return _lineView;
}




/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
